package com.fanpan26.jls.spi;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.AdaptiveClassCodeGenerator;
import org.apache.dubbo.common.extension.ExtensionLoader;

import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;

/**
 * @author fanpan26
 * @description DubboSpiApplication
 */
public class DubboSpiApplication {

    public static void main(String[] args) {

        URL url = URL.valueOf("test://localhost/test?human=en");
        Human humanDefault = ExtensionLoader.getExtensionLoader(Human.class).getDefaultExtension();

        Human humanExtension = ExtensionLoader.getExtensionLoader(Human.class).getExtension("cn");

        Human humanAdaptive = ExtensionLoader.getExtensionLoader(Human.class).getAdaptiveExtension();

        List<Human> humanActivate = ExtensionLoader.getExtensionLoader(Human.class).getActivateExtension(url,"human");

        //default
        System.out.println(humanDefault.sayHello(url));

        Chinese chinese = (Chinese)humanDefault;

        System.out.println("我的朋友说："+chinese.getFriend().sayHello(url));
        //adaptive
        System.out.println(humanAdaptive.sayHello(url));

        for (Human human : humanActivate){
            System.out.println(human.sayHello(url));
        }

      System.out.println( new AdaptiveClassCodeGenerator(Human.class, "human").generate());
    }
}
